<html>
<head><meta charset="utf-8"><title>Allow suppressing unsupported FFI calls (#1807) · miri · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/index.html">miri</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html">Allow suppressing unsupported FFI calls (#1807)</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239668822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/239668822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lander Brandt <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#239668822">(May 20 2021 at 22:30)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> hope it's ok to ping you here. With regards to <a href="https://github.com/rust-lang/miri/issues/1807">https://github.com/rust-lang/miri/issues/1807</a> I was taking a stab at implementing panicking instead of raising an error, and unfortunately I think you were right that panicking right before an FFI call may not work:</p>
<div class="codehilite" data-code-language="error"><pre><span></span><code>   --&gt; C:\Users\lander\.rustup\toolchains\miri\lib\rustlib\src\rust\library\core\src\panicking.rs:42:6
    |
42  |     }
    |      ^ accessing a dead local variable
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

    = note: inside `core::panicking::panic` at C:\Users\lander\.rustup\toolchains\miri\lib\rustlib\src\rust\library\core\src\panicking.rs:42:6
</code></pre></div>
<p>The patch is very straightforward: <a href="https://gist.github.com/landaire/d1351ba8cf2f5dd23db0d0c7dc553f77">https://gist.github.com/landaire/d1351ba8cf2f5dd23db0d0c7dc553f77</a></p>



<a name="239863918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/239863918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#239863918">(May 22 2021 at 10:45)</a>:</h4>
<p><span class="user-mention" data-user-id="410528">@Lander Brandt</span> hm, that is not the kind of UB I expected... this seems to be inside the panic runtime?</p>



<a name="239863926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/239863926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#239863926">(May 22 2021 at 10:45)</a>:</h4>
<p>I think something else is going wrong.</p>



<a name="239864034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/239864034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#239864034">(May 22 2021 at 10:47)</a>:</h4>
<p>the fact that you just pass <code>None</code> for the cleanup block is somewhat suspicious, but I am not sure if that could cause this problem</p>



<a name="239864155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/239864155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#239864155">(May 22 2021 at 10:49)</a>:</h4>
<p>ah, the main issue is that you are falling through to returning <code>true</code></p>



<a name="239864161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/239864161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#239864161">(May 22 2021 at 10:49)</a>:</h4>
<p>which instructs the caller to please jump to the return block</p>



<a name="239864170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/239864170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#239864170">(May 22 2021 at 10:49)</a>:</h4>
<p>which you dont want -- you have to return <code>false</code> in this match arm</p>



<a name="240113665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/240113665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lander Brandt <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#240113665">(May 24 2021 at 21:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20.28.231807.29/near/239864170">said</a>:</p>
<blockquote>
<p>which you dont want -- you have to return <code>false</code> in this match arm</p>
</blockquote>
<p>Just getting back around to this. Thank you, that works! I did originally pass the stack info to the panic handler but removed it as i thought it may cause weirdness in unwinding or something. This is great.</p>
<p>The next issue I need to solve is, AFAIK the config is lost in  <code>eval::create_ecx</code> and I believe I would want to add another property to the <code>InterpCx</code> object, but that comes from <code>rustc_middle</code>. Should a change be made there to pass in <code>config.panic_on_unsupported_functionality</code> so that flag is available from <code>EvalContextExt::emulate_foreign_item_by_name</code> (and other related unsupported feature sites), or is there a better solution?</p>



<a name="240132102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/240132102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lander Brandt <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#240132102">(May 25 2021 at 01:04)</a>:</h4>
<p>Ah I think this is a viable solution: <a href="https://gist.github.com/landaire/f0180e12b0b6c8a167f9f19ebb86e978">https://gist.github.com/landaire/f0180e12b0b6c8a167f9f19ebb86e978</a></p>



<a name="240150777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/240150777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#240150777">(May 25 2021 at 07:21)</a>:</h4>
<p>there's a <code>MiriConfig</code> struct that has a field for each ´-Zmiri` command-line option</p>



<a name="240223739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/240223739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lander Brandt <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#240223739">(May 25 2021 at 17:38)</a>:</h4>
<p>I did add it there but the <code>MiriConfig</code> is not available in the <code>emulate_foreign_item_by_name</code> context. The full diff at this time looks like this: <a href="https://gist.github.com/landaire/384730420647dec9a3f016e126945ebf">https://gist.github.com/landaire/384730420647dec9a3f016e126945ebf</a></p>



<a name="240306363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/269128-miri/topic/Allow%20suppressing%20unsupported%20FFI%20calls%20%28%231807%29/near/240306363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/269128-miri/topic/Allow.20suppressing.20unsupported.20FFI.20calls.20(.231807).html#240306363">(May 26 2021 at 10:55)</a>:</h4>
<p>yeah, MiriConfig is the initial config used to create the evaluator object, so the field needs to be carried over to that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>